package org.feng.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.feng.entity.Role;
import org.feng.mapper.RoleMapper;
import org.feng.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author feng
 * @since 2020-12-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public void saveMenu(String id, String ids) {
        roleMapper.deleteMenu(id);
        if (ids != null && !ids.equals("")) {
            String[] split = ids.split(",");
            ArrayList<HashMap<String, Object>> list = new ArrayList<>();
            for (String menuId : split) {
                HashMap<String, Object> map = new HashMap<>(2);
                map.put("id", id);
                map.put("menuId", menuId);
                list.add(map);
            }
            roleMapper.saveMenu(list);
        }

    }

    @Override
    public List<String> hasMenu(String id) {
        return roleMapper.hasMenu(id);
    }
}
